import os
from collections import defaultdict
if __name__ == '__main__':
    compression_time_list = defaultdict(list)
    decompression_time_list = defaultdict(list)
    is_add_to = 0
    sample_rate = 0.001
    maximum_x_plus1 = 28
    for s_percent in [0.001, 0.01, 0.1]:
        for x in range(5):
            compression_time_list[s_percent].append(0)
            decompression_time_list[s_percent].append(0)
        for x in range(5, maximum_x_plus1):
            os.system(f"./benchmark_dgc_nvcc.o {x} {s_percent} {sample_rate} {is_add_to}")
            with open('ret.txt', 'r') as f:
                compression_time_list[s_percent].append(float(f.readline().strip()))
                decompression_time_list[s_percent].append(float(f.readline().strip()))
    
    with open('benchmark_dgc.csv', 'w') as f:
        f.write(f"""Benchmark DGC:
params:
    is_add_to = {is_add_to},
    sample_rate = {sample_rate}
""")
        f.write(','.join(list(map(str,['CT(us)',0.001,0.01,0.1])))+'\n')
        for x in range(5, maximum_x_plus1):
            f.write(f"{x},")
            f.write(','.join(list(map(str,[compression_time_list[s_percent][x] for s_percent in [0.001, 0.01, 0.1]]))))
            f.write('\n')
        f.write('\n')
        f.write(','.join(list(map(str,['DT(us)',0.001,0.01,0.1])))+'\n')
        for x in range(5, maximum_x_plus1):
            f.write(f"{x},")
            f.write(','.join(list(map(str,[decompression_time_list[s_percent][x] for s_percent in [0.001, 0.01, 0.1]]))))
            f.write('\n')
    print(f"compression_time={compression_time_list}")
    print(f"decompression_time={decompression_time_list}")
                
        